/**
 * Created by bethinner on 8/30/16.
 */
import React, { Component } from 'react';



export default class BarcodeView extends Component{
    constructor(props){
        super(props);
       
    }

    componentWillMount(){

    }

    componentDidMount(){
        this.code93(this.props.code);
        //console.log(this.props.code);
    }
    shouldComponentUpdate(nextProps, nextState) {
        this.code93(nextProps.code);
        return true;
    }

    scaleBarcode(){
        $("#scaleWrap").show();
        $("#navigationBar").hide();
    }
    closeScale(){
        $("#scaleWrap").hide();
        $("#navigationBar").show();

    }


    render(){
        return(
            <div style={{width:"100%"}}>

                <div id="bcTarget" className="barcodeImg" style={{margin:"0 auto"}}  onClick={this.scaleBarcode.bind(this)}>
                </div>



                <div id="scaleWrap" style={{display:"none",width:"100%",height:"100%",background:"white",position:"absolute",top:"0",left:"0",zIndex:9999}}>
                    <div className="rotate90" id="scaleBarcode" style={scaleStyle}>
                    </div>
                    <a href="javascript:void(0)" onClick={this.closeScale.bind(this)} style={{position:"absolute",right:0,top:55}} className="weui_btn weui_btn_mini weui_btn_primary">返回</a>
                </div>
            </div>
        )
    }

    code93(code){
        if($.fn.barcode){
            var scale=2;
            if(this.props.code.length>9)
                scale=1;
            $("#bcTarget").empty().barcode(code, "code93",{barWidth:scale, barHeight:80,showHRI:false,output:"css"});

            $("#scaleBarcode").empty().barcode(code, "code93",{barWidth:2, barHeight:80,showHRI:false,output:"css"});
        }

    }

}

let scaleStyle={
}
BarcodeView.defaultProps = {
    code:""
}

BarcodeView.propTypes = {
    //code:React.PropTypes.string
}


